<!DOCTYPE html>
<html>
    <head>
        <title>JavaScript Audio Write Example</title>
    </head>
    <body>
        <!--
        <audio id="audio-element"
            src="mic/test.mp3"
            controls="true"
            style="width: 512px;">
        </audio>
        -->
        <script>
            /*
            // Detect if the audio context is supported.
            window.AudioContext = (
                window.AudioContext ||
                window.webkitAudioContext ||
                null
            );
            
            if (!AudioContext) {
                throw new Error("AudioContext not supported!");
            }
            
            //create a new audio context
            var ctx = new AudioContext();
            
            //create a audioGainNode to control the main volume
            var mainVolume = ctx.createGain();
            //connect an object with a sound source and a volume control
            var sound = {};
            sound.source = ctx.createBufferSource();
            sound.volume = ctx.createGain();
            
            //connect the sound to the volume control
            sound.source.connect(sound.volume);
            //hook up the sound volume control to the main volume
            sound.volume.connect(mainVolume);
            
            //make the sound source loop
            sound.source.loop = true;
            
            //load a sound file using an ArrayBuffer XMLHttpRequest
            var request = new XMLHttpRequest();
            request.open("GET", 'mic/test.mp3', true);
            request.responseType = 'arraybuffer';
            request.onload = function(e) {
                
                //create a buffer from the response ArrayBuffer
                var buffer = ctx.createBuffer(this.response, false);
                sound.buffer = buffer;
                
                //make the sound source use the buffer and start playing it
                sound.source.buffer = sound.buffer;
                sound.source.start(ctx.currentTime);
                
            };
            
            request.send();
            */
        </script>
        <script>
            
            var audio = document.createElement("audio");
            var source = document.createElement("source");
            source.src = 'mic/test.mp3';
            audio.appendChild(source);
            audio.play();
            
        </script>
        
        <script>
            /*
            function Sound(name) {
                this.name = name;
                this.audio = document.createElement('audio');
                var source = document.createElement('source');
                source.src = 'mic/' + name + '.mp3';
                this.audio.appendChild(source);
            }
            
            Sound.prototype.play = function() {
                this.stop();
                this.audio.play();
            };
            
            Sound.prototype.repeat = function() {
                this.audio.loop = true;
                this.audio.play();
            };
            
            Sound.prototype.stop = function() {
                this.audio.repeat = false;
                this.audio.currentTime = 0;
                this.audio.pause();
            };
            
            var Sounds = {
                all: [
                    'test'
                    //'bubble','buzz','click','donk',
                    //'drip','guitar','knock','scratch',
                    //'snick','spring','swish'
                ]
            };
            Sounds.all.forEach(function(sound) {
              Sounds[sound] = new Sound(sound);
            });
            */
        </script>
    </body>
</html>